<?php

include_once(APP_URL.'protected/lib/private/Check.php');
include_once(APP_URL.'protected/lib/private/Str.php');

class TestController extends BaseController {

    public function actionGenAccount() {
        // http://www.maptopro.com/test/GenAccount

        $email = Str::getRandom(6).'@maptopro.com';
        $password = Str::getRandom(6);

        // email registered and verified
        $condArr = array(
            'select' => array('id'),
            'condition' => 'email=:email AND verified=:verified',
            'params' => array('email' => $email, 'verified' => 1)
        );
        $TblUser = new TblUser();
        $result = $TblUser->selectRecord($condArr);
        if($result) {
            echo Resp::retFail(-2, 'email registered');
            exit;
        }

        // email not registered and not verified
        $verifyCode = md5(microtime());
        $contArr = array(
            'email' => $email,
            'password' => md5($password),
            'verify_code' => $verifyCode,
            'verified' => 1
        );
        if(!$TblUser->addRecord('user', $contArr)) {
            echo Resp::retFail(-1, 'add user failed');
            exit;
        }

        echo $email,' ',$password;
    }
}
